package com.yc.boot.sys.api;

import com.yc.boot.common.model.response.Outcome;
import com.yc.boot.sys.business.SysUtilBusiness;
import com.yc.boot.sys.model.ImgVerification;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 杨智杰
 * @since 2021/8/20 9:52
 */
@Api(tags = "系统工具")
@RestController
@RequestMapping("/sys/util")
public class SysUtilApi {

    @Resource
    private SysUtilBusiness sysUtilBusiness;

    @GetMapping("/getImgVc")
    @ApiOperation("获取一个图片验证码")
    public Outcome<ImgVerification> getImgVc() {
        return Outcome.success(sysUtilBusiness.getVerificationCode());
    }

    @GetMapping("/checkVc")
    @ApiOperation("校验图片验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "序列号", name = "serial", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(value = "验证码", name = "code", dataTypeClass = String.class, required = true)
    })
    public Outcome checkVc(@RequestParam("serial") String serial, @RequestParam("code") String code) {
        return sysUtilBusiness.verifyCode(serial, code) ? Outcome.success("验证成功!") : Outcome.failure("验证码错误!");
    }

}
